package com.stud.system.service.impl;

import com.stud.common.jdbc.MyJdbcTemplate;
import com.stud.common.jdbc.SqlHelp;
import com.stud.common.mybatis.BaseServiceImpl;
import com.stud.system.domain.WorkflowLog;
import com.stud.system.mapper.WorkflowLogMapper;
import com.stud.system.service.WorkflowLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 流程审批记录Service业务层处理
 *
 * @author Stud
 * @date 2023-03-06
 */
@Service
@RequiredArgsConstructor
public class WorkflowLogServiceImpl extends BaseServiceImpl<WorkflowLogMapper, WorkflowLog> implements WorkflowLogService {
    private final MyJdbcTemplate jdbcTemplate;

    @Override
    public List<WorkflowLog> listByWorkflowId(Long workflowId) {
        SqlHelp sqlHelp = SqlHelp.init();
        sqlHelp.append(" select ");
        sqlHelp.append("     t1.id,t1.definition_task_id,t1.task_id,t1.workflow_id,t1.business_id,t1.business_code, ");
        sqlHelp.append("     t1.task_code,t1.task_name,t1.task_type,t1.role_code,t1.user_id, ");
        sqlHelp.append("     t1.user_name,t1.task_status,t1.task_form_status,t1.task_info,t1.flag, ");
        sqlHelp.append("     t1.del_flag,t1.create_by,t1.create_time,t1.update_by,t1.update_time, ");
        sqlHelp.append("     t1.remark, ");
        sqlHelp.append("     t2.role_name ");
        sqlHelp.append(" from t_workflow_log t1 ");
        sqlHelp.append(" left join sys_role t2 on t1.role_code = t2.role_key ");
        sqlHelp.append(" where workflow_id = ? ", workflowId);
        sqlHelp.append(" order by id ");
        return this.jdbcTemplate.select(sqlHelp, WorkflowLog.class);
    }
}
